package com.qf.java2107.yb.hotel.dao.impl;

import com.qf.java2107.yb.hotel.dao.UserDao;
import com.qf.java2107.yb.hotel.pojo.User;
import com.qf.java2107.yb.hotel.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author yb
 * @version 1.0
 * @date 2021-10-27
 **/
public class UserDaoImpl implements UserDao {

    private QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());

    @Override
    public User findByUsername(String username) throws SQLException {

        String sql = "SELECT user_id userId, username,password,nick_name nickName,is_admin isAdmin,phone,gender,user_status userStatus,user_create_time userCreateTime,user_update_time userUpdateTime,is_delete isDelete,is_member isMember,balance FROM t_user WHERE username = ?";

        return queryRunner.query(JdbcUtils.getConnection(), sql, new BeanHandler<>(User.class), username);
    }
}
